(function(app){
	app
		.controller("content_35_inputCtrl",["$scope","$state","myFactory",'$stateParams',"$q",'$timeout','$location','$http','$ionicHistory',function($scope,$state,myFactory,$stateParams,$q,$timeout,$location,$http,$ionicHistory){

			//接收参数
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			$scope.chdrnum01=$stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			//var searchParam = $stateParams.searchParam;
			var initFlag = false;
			var token=sessionStorage.getItem("token");
			
/********************************************初始化函数begin************************************************/
			var item="";
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						$scope.chdrnum01=response.data.data.policy.base.chdrnum01;
						//$scope.item35=response.data.data.modelMap.item35;//后台这里原本就没有返回item35对象的数据
						//item=$scope.item35;
						initFlag = true;
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
/********************************************初始化函数begin************************************************/
			$scope.data = {
				checkFlag: false
			},
			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}	
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//checkbox选择
			$scope.isCheck = function(val){
				if (val) {
					$scope.data.checkFlag = false;
					//alert('未选中')
				} else{
					$scope.data.checkFlag = true;
					//alert('选中')
				};
				console.log($scope.data.checkFlag);				
			}
			//下一步
			$scope.nextStep = function(){
				//$state.go("content_35_list");
				/*$state.go('content_35_list',{
					item:item,chdrnum01:$scope.chdrnum01
				});*/
				//判断是否初始化完成了，如果失败，不予进入下一步
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return false;
				}
				
				var radioFlag=$scope.data.checkFlag;
				//$("#readImage").testRemind("请勾选原保险合同作废声明！");
				if (!radioFlag){
					$.alert({title: '',text: '请勾选原保险合同作废声明！',onOK: function () {}});
					return false;
				}
				/*if(radioFlag){//选择是
					$state.go('content_check_main',{
						item:item,chdrnum01:$scope.chdrnum01
					});
				}*/
				//item.itemId=itemId;
				//item["itemId"] = "35";
				//item={"itemId":"35","itemName":"补发保险合同"};
				item="";
				/*$state.go('content_check_main',{
					itemId:itemId,item:item,chdrnum01:$scope.chdrnum01,chdrcoy:chdrcoy
				});*/
				$ionicHistory.clearCache().then(function(){ 
					$state.go('content_check_main',{
						itemId:itemId,item:item,chdrnum01:$scope.chdrnum01,chdrcoy:chdrcoy
					});
				})

			}
			//返回上一页
			$scope.goBack = function(){
				myFactory.goBack();
			}

			//保单详情
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn35Input','policyWindowOn35Input','policyCloseXOn35Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化查询订单详情
				var policyData;
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}

			//保单详情弹窗关闭
			$scope.policyCancelOn35Input = function(){
				modal('close','policyModalOn35Input','policyWindowOn35Input','policyCloseXOn35Input');
			}
			
			//关闭遮罩
			$scope.overwindowClose = function(){
				//$(".overwindow").show();
				$(".overwindow").hide();
				$(".overmodal").hide();
			}

		}]);

		//指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});

})(app)